home *** CD-ROM | disk | FTP | other *** search
- /*
- * MultiMAIL offline mail reader
- *
-
- Written by Kolossvary Tamas (thomas@vma.bme.hu)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
- #include <signal.h>
- #include <ctype.h>
- #include "interface.h"
-
- mmail mm;
- packet_list *packetList;
- letter_list *letterList;
- Welcome welcome;
- PacketListWindow packets;
- AreaListWindow areas;
- LetterListWindow letters;
- LetterWindow letterwindow;
- HelpWindow helpwindow;
- Interface *interface;
- LittleAreaListWindow *littleareas;
- AddressBook addresses;
- int getstring(WINDOW *, int, int, char *, int, int, int);
-
- WINDOW *screen;
-
- void screen_init(int mode) //mode = 1 ->background, mode = 0 ->no bkgd
- {
- int i, j;
- typedef int line[24];
- typedef line pattern[5];
- pattern text = {{1, 2, 7, 8, 11, 12, 17, 18, 33, 34, 35, 36, 43, 44, 0},
- {1, 2, 3, 6, 7, 8, 11, 12, 13, 16, 17, 18, 32, 33, 36, 37,
- 42, 43, 44, 0},
- {1, 2, 4, 5, 7, 8, 11, 12, 14, 15, 17, 18, 22, 23, 27, 28,
- 32, 33, 36, 37, 41, 43, 44, 0},
- {1, 2, 7, 8, 11, 12, 17, 18, 23, 24, 26, 27, 32, 33, 36, 37,
- 43, 44, 0},
- {1, 2, 7, 8, 11, 12, 17, 18, 24, 25, 26, 29, 30, 33, 34, 35,
- 36, 39, 40, 43, 44, 46, 47, 0}};
-
- /*
- 88 88 88 88 8888 88
- 888 888 888 888 88 88 888
- 88 88 88 88 88 88 88 88 88 88 8 88
- 88 88 88 88 88 88 88 88 88
- 88 88 88 88 888 88 8888 88 88 88
- */
-
- printf("\033(K"); //this is for the special characters
- initscr();
- start_color();
- init_pair(50, COLOR_WHITE, COLOR_BLACK);
- init_pair(51, COLOR_MAGENTA, COLOR_BLACK);
- init_pair(52, COLOR_BLUE, COLOR_BLACK);
- cbreak();
- noecho();
- screen=newwin(0, 0, 0, 0);
- leaveok(screen, TRUE);
- keypad(screen, TRUE);
- wattrset(screen, COLOR_PAIR(50));
- if(mode)
- for(i=0; i<COLS*(LINES-5); i++)
- waddch(screen, ACS_BOARD);
- wattrset(screen, COLOR_PAIR(52) | A_BOLD);
- for(i=0; i < 5; i++)
- {
- j = 0;
- while(text[i][j] != 0)
- {
- mvwaddch(screen, i + 14, text[i][j] + 28,
- ACS_BOARD);
- j++;
- }
- }
-
- wborder(screen, 0, 0, 0, 0, 0, 0, 0, 0);
- mvwaddch(screen, 0, 2, ACS_RTEE);
- wattrset(screen, COLOR_PAIR(50) | A_BOLD);
- waddstr(screen, "MultiMAIL Bluewave reader V0.1");
- wattrset(screen, COLOR_PAIR(52) | A_BOLD);
- waddch(screen, ACS_LTEE);
- wattrset(screen, COLOR_PAIR(51));
- wmove(screen, LINES-5, 1);
- whline(screen, ACS_HLINE, COLS-2);
-
- wnoutrefresh(screen);
- }
-
- void mvwaddchar(WINDOW *window, int y, int x, char c)
- {
- char tmp[2];
-
- tmp[0]=c;
- tmp[1]='\0';
- mvwaddstr(window, y, x, tmp);
- }
-
- void handler(int mittomtenmi)
- {
- nodelay(stdscr, TRUE);
- }
-
- int getstring(WINDOW *window, int y, int x, char *string, int n,
- int bg_color, int fg_color)
- {
- int i;
- char c='\0';
- char tmp[n];
- char tmp2[n];
-
- signal(SIGINT, handler);
- strcpy(tmp2, string);
- wattrset(window, fg_color);
- for(i=0; i<n; i++)
- {
- mvwaddch(window, y, x+i, ACS_BOARD);
- tmp[i]='\0';
- string[i]='\0';
- }
- strcpy(string, tmp2);
- mvwaddstr(window, y, x, string);
- nodelay(stdscr, FALSE);
- leaveok(stdscr, FALSE);
- keypad(stdscr, FALSE);
- refresh();
- wrefresh(window); //to have cursor
- i=0;
- while((c != '\n') && (c != ERR))
- {
- int j;
-
- c=wgetch(stdscr);
- switch(c)
- {
- case ERR : break;
- case '\n': break;
- case '\033': if(wgetch(stdscr) == '[')
- switch(wgetch(stdscr))
- {
- case 'D': // LEFT key
- if(tmp[0] == '\0')
- {
- strcpy(tmp, string);
- i=strlen(string) + 1;
- }
- if(i > 0)
- i--;
- break;
- case 'C': //RIGHT key
- if((i < n-1) && (tmp[i] != '\0'))
- i++;
- break;
- case 51: // DEL
- strncpy(&tmp[i], &tmp[i+1], n-i-1);
- tmp[n-1]='\0';
-
- break;
- }
- nodelay(stdscr, TRUE);
- while(wgetch(stdscr) != ERR);
- nodelay(stdscr, FALSE);
- break;
- case 127: if(i >= 0) //BACKSPACE
- {
- if(i > 0) i--;
- strncpy(&tmp[i], &tmp[i+1], n-i-1);
- tmp[n-1]='\0';
- }
- break;
- default: for(j=n-1; j>i; j--)
- tmp[j]=tmp[j-1];
- tmp[i]=c;
- if(i < n-1) i++;
- break;
- /* FOR TESTS!
- default: mvwprintw(window, y, x, " ");
- mvwprintw(window, y, x, "%3d ", c);
- nodelay(window, TRUE);
- while((c=wgetch(window)) != ERR)
- wprintw(window, "%3d ", c);
- nodelay(window, FALSE); */
- }
- if(c != ERR)
- {
- for(j=0; j<n; j++)
- if(tmp[j] != '\0')
- mvwaddchar(window, y, x+j, tmp[j]);
- else
- mvwaddch(window, y, x+j, ACS_BOARD);
- wmove(window, y, x+i);
- wrefresh(window);
- }
-
- }
- if(c != ERR)
- {
- if(tmp[0] != '\0')
- strcpy(string, tmp);
- wattrset(window, bg_color);
- for(i=0; i<n; i++)
- if(string[i] != '\0')
- mvwaddchar(window, y, x+i, string[i]);
- else
- mvwaddch(window, y, x+i, ' ');
- wmove(window, y, x+i);
- wrefresh(window);
- }
- leaveok(stdscr, TRUE);
- refresh();
- if(c == ERR)
- return -1;
- else
- return 1;
- }
-
- int WarningWindow (char *warning, char *yes, char *no)
- {
- WINDOW *warnwin;
- int x, c, i;
- int def_val = 1; //possible values: 1 or -1
- int result = 0;
-
- init_pair(59, COLOR_WHITE, COLOR_RED);
- init_pair(60, COLOR_YELLOW, COLOR_RED);
-
- x = strlen(warning) + 4;
- warnwin = newwin(7, x, LINES / 2 - 4, (COLS - x) / 2);
- wattrset(warnwin, COLOR_PAIR(59) | A_BOLD);
- for(i=0; i < 7 * x; i++)
- waddch(warnwin, ' ');
- box(warnwin, 0, 0);
-
- while(result == 0)
- {
- wattrset(warnwin, COLOR_PAIR(59) | A_BOLD);
- mvwprintw(warnwin, 4, x/3 - 1, " %s ", &yes[1]);
- mvwprintw(warnwin, 4, 2*x/3 - strlen(no) - 1, " %s ", &no[1]);
- mvwaddstr(warnwin, 2, 2, warning);
- wattrset(warnwin, COLOR_PAIR(60) | A_BOLD);
- if(def_val == 1)
- {
- mvwaddch(warnwin, 4, x/3 - 1, '[');
- mvwaddch(warnwin, 4, x/3 + strlen(yes), ']');
- }
- else
- {
- mvwaddch(warnwin, 4, 2*x/3 - strlen(no) - 1, '[');
- mvwaddch(warnwin, 4, 2*x/3, ']');
- }
- mvwaddch(warnwin, 4, x/3, yes[0]);
- mvwaddch(warnwin, 4, 2*x/3 - strlen(no), no[0]);
- wrefresh(warnwin);
-
- if( (c = tolower(wgetch(screen))) == tolower(yes[0]) )
- {
- delwin(warnwin);
- result = 1;
- }
- else
- if(tolower(c) == tolower(no[0]))
- {
- delwin(warnwin);
- result = -1;
- }
- else
- switch(c)
- {
- case 9: def_val = def_val * (-1); break;
- case '\n': result = def_val; break;
- }
- }
- if(result == 1)
- return 1;
- else
- return 0;
- }
-
- main(int argc, char *argv[])
- {
- int end = 0;
- int c;
-
- if(argc > 1)
- interface = new Interface(0);
- else
- interface = new Interface(1);
-
- while(!end)
- {
- c=wgetch(screen);
- switch(c)
- {
- case 'q': end=interface->back(); break;
- case 'Q': end=interface->back(); break;
- case '\033': end=interface->back(); break; //the escape key
- case KEY_BACKSPACE: end=interface->back();
- case '\n': interface->select(); break;
- case '/': interface->search(); break;
- case KEY_DOWN: interface->DOWN_ARROW(); break;
- case KEY_UP: interface->UP_ARROW(); break;
- case KEY_HOME: interface->HOME_KEY(); break;
- case KEY_END: interface->END_KEY(); break;
- case KEY_PPAGE: interface->PGUP_KEY(); break;
- case KEY_NPAGE: interface->PGDN_KEY(); break;
- case KEY_RIGHT: interface->RIGHT_ARROW(); break;
- case KEY_LEFT: interface->LEFT_ARROW(); break;
- case KEY_F(1): interface->help(); break;
- case 'r': interface->enterletter('R'); break;
- case 'R': interface->enterletter('R'); break;
- case 'o': interface->enterletter('O'); break;
- case 'O': interface->enterletter('O'); break;
- case 'e': interface->enterletter('E'); break;
- case 'E': interface->enterletter('E'); break;
- case 'n': interface->enterletter('N'); break;
- case 'N': interface->enterletter('N'); break;
- case 's': interface->save(); break;
- case 'S': interface->save(); break;
- case 'k': interface->kill(); break;
- case 'K': interface->kill(); break;
- case 'a': interface->addressbook(); break;
- case 'A': interface->addressbook(); break;
- case KEY_F(2): interface->ReplyPacket(); break;
- default: interface->ANY_KEY(); break;
- }
- if(!end) doupdate();
- }
-
- delwin(screen);
- touchwin(stdscr);
- refresh();
- leaveok(screen, FALSE);
- echo();
- system("clear");
- }
-